package com.example.sync;

import ch.qos.logback.core.util.TimeUtil;
import com.example.sync.util.DateUtil;
import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;

import static java.lang.Thread.sleep;

/**
 * @program: Sync
 * @description: a
 * @author: chaidl  ！
 * @create: 2022-01-19 14:54
 */
@Slf4j
public class test {
    static Integer counter = 0;
    public static void main(String[] args) throws InterruptedException {
        String a=(String) null;
        System.out.println(a);

        // Thread t1 = new Thread(() -> {
        //     for (int i = 0; i < 5000; i++) {
        //         counter++;
        //     }
        // }, "t1");
        // Thread t2 = new Thread(() -> {
        //     for (int i = 0; i < 5000; i++) {
        //         counter--;
        //     }
        // }, "t2");
        // t1.start();
        // t2.start();
        // t1.join();
        // t2.join();
        // log.debug("{}",counter);
    }
    private static void test1() throws InterruptedException {
        log.debug("开始运行1...");
        Thread t1 = new Thread(() -> {
            log.debug("开始运行2...");
            try {
                sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            log.debug("运行结束1...");
        }, "daemon");
// 设置该线程为守护线程
        t1.setDaemon(true);
        t1.start();
        sleep(1);
        log.debug("运行结束2...");
    }
    public static void main1(String[] args) {
        String yyyyMMddHHmmss = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now());
        log.info(yyyyMMddHHmmss);
        LocalDateTime now = LocalDateTime.now();
        String format = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss"));
        System.out.println(format);
        String format1 = LocalDateTime.now().plusYears(-1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss"));
        System.out.println("一年前的时间戳"+format1);
        //获取一年前的时间戳
        long start = LocalDateTime.now().plusYears(-1).toInstant(ZoneOffset.of("+8")).toEpochMilli();
        System.out.println(start);
        System.out.println(System.currentTimeMillis());
        long l = LocalDate.now().toEpochDay() - LocalDate.now().toEpochDay();
        System.out.println(l);
        Long startTime=1642583044000L;
        Long end=1611046753000L;
        //计算两个时间段内的时间差
        long l1 = Instant.ofEpochSecond(startTime/1000).atZone(ZoneOffset.ofHours(0)).toLocalDate().toEpochDay() - Instant.ofEpochSecond(end/1000).atZone(ZoneOffset.ofHours(0)).toLocalDate().toEpochDay();
        System.out.println(l1);

    }
    public static long timeToStamp(String timers) {
        Date d = new Date();
        long timeStemp = 0;
        try {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM");
            d = sf.parse(timers);// 日期转换为时间戳
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        timeStemp = d.getTime();
        return timeStemp;
    }
}
